Current Location: Home> Function Categories> mt_rand

mt_rand

Generate better random numbers
Name:mt_rand
Category:math
Programming Language:php
One-line Description:Use the Mersenne Twister algorithm to return random integers.

Definition and usage

mt_rand() uses the Mersenne Twister algorithm to return random integers.

Example

In this example, we will return some random numbers:

 <?php
echo ( mt_rand ( ) ) ;
echo ( mt_rand ( ) ) ;
echo ( mt_rand ( 10 , 100 ) ) ;
?>

Try it yourself

grammar

 mt_rand ( min , max )

illustrate

If no optional parameters min and max are provided, mt_rand() returns a pseudo-random number between 0 and RAND_MAX. For example, if you want a random number between 5 and 15 (including 5 and 15), use mt_rand(5, 15).

Many old libc random number generators have some uncertain and unknown characteristics and are very slow. The rand() function of PHP uses the libc random number generator by default. mt_rand() function is used informally to replace it. This function uses a known feature in Mersenne Twister as a random number generator, which can produce random values ​​at an average speed of four times faster than rand() provided by libc.

Similar Functions
  • Convert radians to corresponding angles rad2deg

    rad2deg

    Convertradianstocorr
  • Natural logarithm log

    log

    Naturallogarithm
  • Arctangle of two parameters atan2

    atan2

    Arctangleoftwoparame
  • Get the pi value pi

    pi

    Getthepivalue
  • Convert angle to radians deg2rad

    deg2rad

    Convertangletoradian
  • Round the division result intdiv

    intdiv

    Roundthedivisionresu
  • Determine whether it is a finite value is_finite

    is_finite

    Determinewhetheritis
  • Generate a random integer rand

    rand

    Generatearandominteg
Popular Articles